package client;

import bean.User;
import exception.ListProductException;
import service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/findUserServlet")
public class FindUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取id
        String id = request.getParameter("id");
        //2.创建UserService对象，
        UserService service = new UserService();
        try {
            //调用service层的根据id查找用户的方法
            User user = service.findUserById(id);
            //3.将user存入request
            request.setAttribute("user",user);
            //4.请求转发到update.jsp
            request.getRequestDispatcher("/update.jsp").forward(request,response);
        } catch (ListProductException e) {
            e.printStackTrace();
        }


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
